package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.example.demo.domain.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;


/**
* @Entity com.example.demo.domain.User
*/
public interface UserMapper extends BaseMapper<User> {

    /**
     * 执行循环脚本
     * @param ids
     * @return
     */
    @Select("<script>" +
            "   select * from user  " +
            "         <if test=\"ids != null and ids.size()>0\">" +
            "               where id in" +
            "                  <foreach collection=\"ids\" item=\"item\" index=\"index\" close=\")\" open=\"(\" separator=\",\"> " +
            "                        #{item} "+
            "                  </foreach>"+
            "        </if>"+
            "</script>")
    public List<User> selectUserListInId(@Param("ids") List<String> ids);


    /**
     * sql 直接执行写法
     * @param sql
     * @return
     */
    @Select("${sql}")
    List<Map<String, Object>> mapStringObjectList(@Param(value = "sql")String sql);


    @Select("<script> " +
            "   select * from user " +
            "           <if test=\"title !=null \">" +
            "                   where username like '%' #{username} '%'" +
            "            </if>  " +
            "</script>")
    List<Map<String, Object>> selectMapObjectList(@Param("username")String username);


    List<User> selectUserPage(Map map);

    List<User> selectUserInIds(String[] ids);

    int updateUserByIds(User user);

    int insertUserOne(User user);
}
